Categories

HT1621 6 Digit 7 segment Display example

This is a 6-digit 7-segment LCD display module and this screen is already widely used in multimeter, electronic scales, electronic clock and ultrasonic distance measurement.

It is suitable for Ar duino motherboard and the other 5V mcu, and it has a backlight which can help you to read the screen clearly in the dark.
Features:

– Compatibility: can be directly connected to Arduino board, 51, AVR board.
– Backlight color: White
– Display Size: 1.4 inch
– Driver IC: HT1621
– Interface: 3-wire SPI
– Working Voltage: 4.7-5.2VDC
– Working Current: 0.4mA without backlight, and 4mA with backlight
– Applications: Thermometers, multimeter, electronic scales, DIY projects, etc.

 

5 Digit 7 segment Display,

5 Digit 7 segment Display

Connection

I used the following connection for the module, you can see the module pins in the image above

Arduino Pin Module Pin
2 CS
3 WR
4 Data
Arduino Gnd Gnd
Arduino 5v Vcc

You can change the Arduino pins if you wish, just remember and change the defines below in the code

#define CS 2 //Pin 2 as chip selection output
#define WR 3 //Pin 3 as read clock output
#define DATA 4 //Pin 4 as Serial data output

Code

There was a lot of incomplete code examples, libraries with examples that did not work but i found this code example that requires no external libraries and worked nicely as a starting point

#define CS   2  //Pin 2 as chip selection output
#define WR   3  //Pin 3 as read clock output
#define DATA 4  //Pin 4 as Serial data output
 
#define CS1    digitalWrite(CS, HIGH) 
#define CS0    digitalWrite(CS, LOW)
#define WR1    digitalWrite(WR, HIGH) 
#define WR0    digitalWrite(WR, LOW)
#define DATA1  digitalWrite(DATA, HIGH) 
#define DATA0  digitalWrite(DATA, LOW)
 
#define sbi(x, y)  (x |= (1 << y))  
#define cbi(x, y)  (x &= ~(1 <<y ))      
#define uchar   unsigned char 
#define uint   unsigned int 
 
#define  ComMode    0x52  
#define  RCosc      0x30  
#define  LCD_on     0x06 
#define  LCD_off    0x04 
#define  Sys_en     0x02 
#define  CTRl_cmd   0x80
#define  Data_cmd   0xa0   
 
 
/*0,1,2,3,4,5,6,7,8,9,A,b,C,c,d,E,F,H,h,L,n,N,o,P,r,t,U,-, ,*/
const char num[]={0x7D,0x60,0x3E,0x7A,0x63,0x5B,0x5F,0x70,0x7F,0x7B,0x77,0x4F,0x1D,0x0E,0x6E,0x1F,0x17,0x67,0x47,0x0D,0x46,0x75,0x37,0x06,0x0F,0x6D,0x02,0x00,};
char dispnum[6]={0x00,0x00,0x00,0x00,0x00,0x00};
 
 
void SendBit_1621(uchar sdata,uchar cnt) 
{ 
  uchar i; 
  for(i=0;i<cnt;i++) 
  { 
    WR0;
    if(sdata&0x80) DATA1; 
    else DATA0;
    WR1;
    sdata<<=1; 
  } 
}
 
void SendCmd_1621(uchar command)
{ 
  CS0; 
  SendBit_1621(0x80,4);   
  SendBit_1621(command,8);
  CS1;                     
}
 
void Write_1621(uchar addr,uchar sdata)
{ 
  addr<<=2; 
  CS0; 
  SendBit_1621(0xa0,3);    
  SendBit_1621(addr,6);     
  SendBit_1621(sdata,8);    
  CS1; 
} 
 
void HT1621_all_off(uchar num)
{
  uchar i; 
  uchar addr=0; 
  for(i=0;i<num;i++) 
  { 
    Write_1621(addr,0x00); 
    addr+=2; 
  } 
}
 
void HT1621_all_on(uchar num)
{
  uchar i; 
  uchar addr=0; 
  for(i=0;i<num;i++) 
  {
    Write_1621(addr,0xff); 
    addr+=2; 
  } 
}
 
void Init_1621(void)
{
  SendCmd_1621(Sys_en);
  SendCmd_1621(RCosc);    
  SendCmd_1621(ComMode);  
  SendCmd_1621(LCD_on);
}    
 
void displaydata(int p)
{
  uchar i=0;
  switch(p)
  {
    case 1:
    sbi(dispnum[0],7);
    break;
    case 2:
    sbi(dispnum[1],7);
    break;
    case 3:
    sbi(dispnum[2],7);
    break;
    default:break;
  }
  for(i=0;i<=5;i++) 
  {
    Write_1621(i*2,dispnum[i]);
  }
}
 
 
 
void setup() {
  pinMode(CS, OUTPUT); // 
  pinMode(WR, OUTPUT); // 
  pinMode(DATA, OUTPUT); //
  CS1;
  DATA1;
  WR1;
  delay(50);
  Init_1621();
  HT1621_all_on(16); 
  delay(1000);
  HT1621_all_off(16);
  delay(1000);
 
  displaydata(1);//light on the first decimal point starting from the right side
  dispnum[5]=num[5];
  dispnum[4]=num[4];
  dispnum[3]=num[3];
  dispnum[2]=num[2];
  dispnum[1]=num[1];
  dispnum[0]=num[0];
 
  sbi(dispnum[5],7);  
  //cbi(dispnum[5],7);
  sbi(dispnum[4],7);   
  //cbi(dispnum[4],7); 
  sbi(dispnum[3],7);   
  //cbi(dispnum[3],7); 
 
 
 
  Write_1621(0,num[0]);  //0
  Write_1621(2,num[1]);  //1
  Write_1621(4,num[2]);  //2
  Write_1621(6,num[3]);  //3
  Write_1621(8,num[4]);  //4
  Write_1621(10,num[5]); //第5
 
}
 
void loop() {
  // put your main code here, to run repeatedly:
 
}

 

Pretty straightforward, you should see 543210 on your display

 

Links

Fairly low cost for an LCD, coming in at about $5
LCD Module 2.4 inch 6-Digit 7 Segment LCD Display Module HT1621 LCD Driver IC with Decimal Point White Backlight for Arduino

Share

Arduino tip sampling analog data

Sampling sata is particularly useful for analog sensors such as an LDR or a thermistor

You can change the amount of samples to take and the interval which is in millioseconds

int sampleData(int analogPin, int samples = 10, int sampleInterval = 100) 
{ 
int sampleData[samples];
int val = 0;
for (int i = 0; i<samples; i++) 
{
sampleData[i] = analogRead(analogPin);
val = val + sampleData[i];
delay(sampleInterval);
}
val = (val / samples);
return map(val, 550, 1023, 100, 0);
}
Share

3 channel tracking sensor example

This Tracking Sensor for Arduino can detect the white lines in black and black lines in white. This particular module has 3 sensors

Using infrared light detection, anti-interference ability
Built-in LED indicator lights
Sensor CTRT5000, high sensitivity, stable performance
Operating voltage 5V, output low black line, white line output high

 

Connection

Module Pin Arduino pin
 Vcc  5v
 L  Arduino Pin 4
 C  Arduino Pin 5
 R  Arduino Pin 6
 Gnd  Gnd

 

Code

// connect the sensors to digital pins
#define LEFT_SENSORPIN 4
#define CENTER_SENSORPIN 5
#define RIGHT_SENSORPIN 6
 
void setup()
{
  Serial.begin(9600);
  pinMode(LEFT_SENSORPIN,INPUT);
  pinMode(CENTER_SENSORPIN,INPUT);
  pinMode(RIGHT_SENSORPIN,INPUT);
}
 
void loop()
{
  // read input from sensors
  byte leftSensor=digitalRead(LEFT_SENSORPIN);
  byte centerSensor=digitalRead(CENTER_SENSORPIN);
  byte rightSensor=digitalRead(RIGHT_SENSORPIN);
 
  Serial.print(" Left : ");
  Serial.print(leftSensor);
  Serial.print(" Centre : ");
  Serial.print(centerSensor);
  Serial.print(" Right : ");
  Serial.print(rightSensor);
  Serial.println();
  delay(1000);
}

 

Links

5V 3 Channel Infrared Line Track Tracking Tracker Sensor Module For Arduino

Share

Arduino and GP2Y0A21YK Distance Sensor

the GP2Y0A21 is an infrared proximity sensor made by Sharp. Part # GP2Y0A21YK has an analog output that varies from 3.1V at 10cm to 0.4V at 80cm. The sensor has a Japanese Solderless Terminal (JST) Connector.

FEATURES

• Digital Output
• LED Pulse Cycle Duration: 32 ms
• Range: 10 to 80 cm
• Typical response time: 39 ms
• Typical start up delay: 44 ms
• Average Current Consumption: 30 mA
• Detection Area Diameter @ 80 cm: 12 cm

 

Schematic

Code

/*  
VCC -- VCC  
GND -- GND  
Signal -- Analog 0 
 */
 
#define pin A0
 
void setup () 
{
  Serial.begin (9600);
  pinMode (pin, INPUT);
}
 
void loop () 
{
  uint16_t value = analogRead (pin);
  uint16_t range = get_gp2d12 (value);
  Serial.println (value);
  Serial.print (range);
  Serial.println (" mm");
  Serial.println ();
  delay (1000);
}
 
uint16_t get_gp2d12 (uint16_t value) 
{
  if (value < 10) value = 10;
  return ((67870.0 / (value - 3.0)) - 40.0);
}

 

Link
GP2Y0A21YK0F GP2Y0A21 Infrared Proximity Sensor IR Analog Distance Sensor VE713 P

Share