--> August 2017 | basic arduino tutorial

Friday, August 25, 2017

Project III - 9. Thermostat using 7 Segment Display based On Arduino

Project III - 9. Thermostat using 7 Segment Display based On Arduino

Thermostat using 7 Segment Display


Thermostat is a tool used to maintain the temperature in accordance with the set point that has been determined. The temperature is read by the LM35 sensor and the results are displayed on seven segments. Seven segment consists of 4 digits, 2 digits to display the readable temperature and 2 digits to display the unit degree celsius. While set point in setting by using 3 button. The SET button is used to enter in the set point set menu. UP button used to add / raise setpoint. While the DOWN button is used to reduce the setpoint. The heater / controller in its ON / OFF control uses a relay connected to the output leg of the Arduino.

Hardware Requirement
  • Arduino Uno Board
  • LM35 Module
  • 4 Digit of 7-Segment with Common Anode
  • Relay 1 Channel Module
  • 3 Push Button
  • Power supply +5 Volt
  • Jumper


LM35 Sensor | Source                   Relay 1 Channel | Source


Element Heater | Source


Block Diagram


Schematic





Arduino - 7 Segment Wiring



Arduino - LM35 Wiring



Arduino - Relay Wiring



 Arduino - Buttons Wiring



Source Code/Sketch

int adc,T,setPoint;
byte setSP, f_awal, kedip;
long lastButton = 0;
long delayAntiBouncing = 50;
byte seven_seg_digits[12][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 }, // = 9
{ 0,0,1,1,1,0,0 }, // = derajat
{ 0,1,1,0,0,0,1 } // = C
};
void setup(){
for(char i=2; i<13; i++){
pinMode(i,OUTPUT);
}
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
pinMode(A4,OUTPUT);
setPoint=40;
}
void loop(){
adc = analogRead(0);
T = (adc*5)/10;
tampilSuhu();
tampilC();
if(T<(setPoint-1) || f_awal==0){
digitalWrite(A4,HIGH);
f_awal=1;
}
else if(T>=setPoint){
digitalWrite(A4,LOW);
}
tombol();
}
void tampilSuhu(){
digitalWrite(10,LOW); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
if (setSP==1){
sevenSegWrite(setPoint/10);
}
else{
sevenSegWrite(T/10);
}
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,LOW);
digitalWrite(12,HIGH); digitalWrite(13,HIGH);
if (setSP==1){
sevenSegWrite(setPoint%10);
}
else{
sevenSegWrite(T%10);
}
delay(5);
}
void tampilC(){
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,LOW); digitalWrite(13,HIGH);
sevenSegWrite(10);
delay(5);
digitalWrite(10,HIGH); digitalWrite(11,HIGH);
digitalWrite(12,HIGH); digitalWrite(13,LOW);
sevenSegWrite(11);
delay(5);
}
void sevenSegWrite(byte segment) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[segment][segCount]);
++pin;
}
}
void tombol(){
if(digitalRead(A1)==0){
if ((millis() - lastButton) > delayAntiBouncing){
setSP=1;
}
lastButton = millis();
}
while (setSP){
//-----------------tombol seting
if(digitalRead(A1)==0){
if ((millis() - lastButton) > delayAntiBouncing){
setSP=0;
}
lastButton = millis();
}
//---------------tombol up
else if(digitalRead(A2)==0){
if ((millis() - lastButton) > delayAntiBouncing){
setPoint++;
}
lastButton = millis();
}
//---------------tombol down
else if(digitalRead(A3)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (setPoint>0){
setPoint--;
}
}
lastButton = millis();
}
if (kedip<30){
tampilC();
}
else{
tampilSuhu();
tampilC();
if(kedip>60)kedip=0;
}
++kedip;
}
setSP=0;
}

How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script pr
5.  Normal view displays the readable temperature.



6. The heater will be ON when the temperature is below the set point, the initial set point is 40°C.
7. Heater OFF when the temperature is equal to set point.
8. Heater will light up again after the temperature decreases 5° C below the set point.
9. To set the set point by pressing the SET button, so the seven segment displays the setpoint temperature

     And flashing.


10. Press UP button to increase set point temperature or press DOWN button to decrease it.
11. Press the SET button when the settings are done.


Video for Project III - 9. Thermostat using 7 Segment Display based On Arduino





Required file

Thursday, August 24, 2017

Project I - 14. Queue Machine (2 Counters) with 7 Segment Display Based on Arduino

Project I - 14. Queue Machine (2 Counters) with 7 Segment Display Based on Arduino

Queue Machine (2 Counters) with 7 Segment Display


Queue machine 2 counters with seven segment display 2 digit on each counter also equipped with sound queue output. The counter clerk pressed the NEXT button to dial the queue number, simultaneously 7-segment will display the queue number and the queue number sound will be heard according to the current number.

There are 2 buttons on each counter, NEXT button to call the next queue number, while RETURN button to repeat the call without adding queue number. Seven segment displays queue sequence and counter number. Sound is generated from IC ISD17xx, voice queue number recorded on the IC then Arduino access address of voice number using SPI communication.


Hardware Requirement
  • Arduino Uno Board
  • 4 Digit of 7-Segment with Common Anode
  • RTC DS1307 Module
  • 4 Push Button
  • Speaker 0.5W 80 Ohm
  • ISD17xx (ISD 17180 is recomended)
  • Power supply +5 Volt
  • Jumper

7-Segment | Source                               Push Button | Source



ISD 17180 | Source


Speaker | Source


Block Diagram


Schematic


7-Segment CA Wiring | Source


Arduino - 7 Segment Wiring


Arduino - Buttons Wiring


Arduino - ISD Module Wiring

#include <Wire.h>
#define DS1307_ADDRESS 0x68
byte zero = 0x00;
byte nilai, i, f_kpd, menu;
byte second ,minute,hour, weekDay;
byte monthDay,month,year;
word kedip;
long lastButton = 0;
long delayAntiBouncing = 50;
byte seven_seg_digits[10][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,0,1,0,0 } // = 9
};
void setup()
{
pinMode(2, OUTPUT); //a
pinMode(3, OUTPUT);//b
pinMode(4, OUTPUT);//c
pinMode(5, OUTPUT);//d
pinMode(6, OUTPUT);//e
pinMode(7, OUTPUT);//f
pinMode(8, OUTPUT);//g
pinMode(9, OUTPUT);//dig 1
pinMode(10, OUTPUT);//dig 2
pinMode(11, OUTPUT);//dig 3
pinMode(12, OUTPUT);//dig 4
pinMode(13, OUTPUT);//dig 5
pinMode(A0, OUTPUT);//dig 6
pinMode(A1,INPUT);
pinMode(A2,INPUT);
pinMode(A3,INPUT);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
Wire.begin();
}
void loop(){
bacaRTC();
tampilJam();
tampilMenit();
tampilDetik();
cekTombol();
}
void tampilJam(){
digitalWrite(9,LOW); digitalWrite(10,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
digitalWrite(13,HIGH); digitalWrite(A0,HIGH);
sevenSegWrite(hour/10);
delay(3);
digitalWrite(9,HIGH); digitalWrite(10,LOW);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
digitalWrite(13,HIGH); digitalWrite(A0,HIGH);
sevenSegWrite(hour%10);
delay(3);
}
void tampilMenit(){
digitalWrite(9,HIGH); digitalWrite(10,HIGH);
digitalWrite(11,LOW); digitalWrite(12,HIGH);
digitalWrite(13,HIGH); digitalWrite(A0,HIGH);
sevenSegWrite(minute/10);
delay(3);
digitalWrite(9,HIGH); digitalWrite(10,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,LOW);
digitalWrite(13,HIGH); digitalWrite(A0,HIGH);
sevenSegWrite(minute%10);
delay(3);
}
void tampilDetik(){
digitalWrite(9,HIGH); digitalWrite(10,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
digitalWrite(13,LOW); digitalWrite(A0,HIGH);
sevenSegWrite(second/10);
delay(3);
digitalWrite(9,HIGH); digitalWrite(10,HIGH);
digitalWrite(11,HIGH); digitalWrite(12,HIGH);
digitalWrite(13,HIGH); digitalWrite(A0,LOW);
sevenSegWrite(second%10);
delay(3);
}
void sevenSegWrite(byte segment) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[segment][segCount]);
++pin;
}
}
byte decToBcd(byte val){
return ( (val/10*16) + (val%10) );
}
byte bcdToDec(byte val) {
return ( (val/16*10) + (val%16) );
}
void cekTombol(){
do{
//------------------------SET
if (digitalRead(A1)==0){
if ((millis() - lastButton) > delayAntiBouncing){
f_kpd=1;
menu++;
}
lastButton = millis();
}
//---------------------------up
else if(digitalRead(A2)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (menu==1){
++hour;
if (hour==24){
hour=0;
}
}
else if(menu==2){
++minute;
if (minute==60){
minute=0;
}
}
else if(menu==3){
++second;
if (second==60){
second=0;
}
}
}
lastButton = millis();
}
//----------------------------DOWN
else if(digitalRead(A3)==0){
if ((millis() - lastButton) > delayAntiBouncing){
if (menu==1){
--hour;
if (hour==255){
hour=23;
}
}
else if(menu==2){
--minute;
if (minute==255){
minute=59;
}
}
else if(menu==3){
--second;
if (second==255){
second=59;
}
}
}
lastButton = millis();
}
if (menu==1 && kedip<30){
tampilMenit();
tampilDetik();
}
else if (menu==2 && kedip<30){
tampilJam();
tampilDetik();
}
else if (menu==3 && kedip<30){
tampilJam();
tampilMenit();
}
else{
tampilJam();
tampilMenit();
tampilDetik();
if(kedip>60)kedip=0;
}
++kedip;
if (menu==4){
setingRTC();
f_kpd=0;
}
}
while(f_kpd);
menu=0;
}
void bacaRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read() & 0b111111);
weekDay = bcdToDec(Wire.read());
monthDay = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
void setingRTC(){
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(zero); //stop RTC
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekDay));
Wire.write(decToBcd(monthDay));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(zero); //start
Wire.endTransmission();
}


How it Works

1. Connect the Arduino with Peripherals needed.
2. Plug in the Power Source on the device.

3. Add some library if needed
4. Compile and upload the script program above to your arduino.
5. The first display on the seven segment
6. Press the Next button on the counter 1, the queue number will be increases and the counters display of the show 
    1, ISD issues a queue sound according to the one in the display along with the counter number



7. Press the Next button on the counter 2, the queue number increases by 1 and the counter shows the number 2


8. Press the Return button to redial the queue number without adding the queue sequence number.



Video for Project I - 14. Queue Machine (2 Counters) with 7 Segment Display Based on Arduino





Requried file