Thursday, August 19, 2021

Arduino Analog Input and Display

 

Introduction

Arduino Uno has up to six analog input pins. Each analog inputs has resolution of 10-bit (0 – 1023). By default its reference voltage is 5V.

Within this example, we use analog reading on A0 and show its voltage level on seven segment display.

Arduino Analog Input and Display
Schematic Diagram
 

Arduino Programming

Arduino analogRead() function perform an analog voltage reading on any analog pin ranges from A0 to A5. Here we use A0 pin to read input voltage. We use a DIY Arduino shield for this example.

/* Main.ino file generated by New Project wizard
*
* Created: Tue Dec 4 2018
* Processor: Arduino Uno
* Compiler: Arduino AVR
*/
#define POT A0
#define BUZ 6
char ssd[10]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int cnt=0;
void displays(char cnt){
digitalWrite(7,bitRead(ssd[cnt],0));
digitalWrite(8,bitRead(ssd[cnt],1));
digitalWrite(9,bitRead(ssd[cnt],2));
digitalWrite(10,bitRead(ssd[cnt],3));
digitalWrite(11,bitRead(ssd[cnt],4));
digitalWrite(12,bitRead(ssd[cnt],6));
digitalWrite(13,bitRead(ssd[cnt],5));
}
void setup()
{ // put your setup code here, to run once:
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(BUZ,OUTPUT);
}
void loop()
{ // put your main code here, to run repeatedly:
int readA0=analogRead(POT);
delay(100);
cnt=(float)readA0*5.0/1023;
if(cnt>3) digitalWrite(BUZ,HIGH);
else digitalWrite(BUZ,LOW);
displays(cnt);
}


Click here to download this example package.




No comments:

Post a Comment

Labels

ADC (10) Analog (14) Arduino (12) Atmega16 (19) Audio (2) AVR (20) Charger (1) Cortex-M0 (1) Counter (10) CPLD (25) Digital I/O (22) Display (34) EEPROM (2) Environment Sensor (1) esp8266 (2) Experiment Board (10) I2C (4) Interrupt (7) LCD (1) LDmicro (29) measurement and instrumentation (7) Microchip Studio (3) MikroC (1) One-Shot (3) OpAmp (1) PCB (31) PIC16 Microcontrollers (16) PIC16F877A (2) PIC16F887 MikroC (22) PLC (35) PWM (11) Regulator (1) RTC (2) Sensor (8) Shift Registers (5) SPI (5) Timer (34) UART (2) ultra-sonic sensor (1) USB (1) VHDL (21) xc8 (1) XC95108 (9) XC9536 (15) XC9572 (1) Xilinx (23) Xilinx ISE (22)