c++ arduino serial communication
Serial Communication with C++ Project. C++ windows application
with Arduino nano Communication Serial A photoresistor or light-dependent
Communicating to the Arduino in the .NET platform is pretty much straightforward: The Arduino uses a virtual serial
port to allow programs to be written onto it, but we can also use this port to get and send data to and from the Arduino.
Parts Required:
- Arduino NANO
- LDR (1)
- LCD 16×2 (1)
- Wires to connect it all together
#include <LiquidCrystal.h>
const int buttonPin = A2;
const int ledPin = 8;
int buttonState = 0;
int ledstat = 0;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorMin = 0;
const int sensorMax = 600;
void setup() {
pinMode(buttonPin, INPUT);
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
}
void loop() {
lcd.setCursor(0, 1);
int sr = analogRead(A2);
// map the sensor range to a range of four options:
int range = map(sr, 0, 1023, 0, 255);
lcd.print(sr);
delay(65);
lcd.clear();
if (sr < 5){
Serial.print(0);
}
else
Serial.println(1);
}
For more Please make sure to subscribe to Officialhrm YouTube channel and like Facebook Page.
Thank you for visiting Officialhrm! Please don’t forget to share this website with your friends.