Basics of Microcontrollers
CC3200 Micrcontroller LED Blinking code.
void setup()
{
pinMode(11,INPUT_PULLUP);
pinMode(29,OUTPUT);
}
void loop()
{
int x=digitalRead(11);
if(x==1)
{
digitalWrite(29,HIGH);
}
else
{
digitalWrite(29,LOW);
}
}
1) UART TEMPERATURE AND LED PIN DIAGRAM WITH CODE
//First MC Code
#define TEMP_SENSOR A0 // TMP36 connected to A0
void setup() {
Serial.begin(9600); // Start Serial communication
}
void loop() {
int sensorValue = analogRead(TEMP_SENSOR); // Read sensor value
float voltage = sensorValue * (5.0 / 1024.0); // Convert to voltage
float temperature = (voltage - 0.5) * 100.0; // Convert to Celsius
byte *tempBytes = (byte *)&temperature; // Get the float bytes
Serial.write(tempBytes, sizeof(float)); // Send all 4 bytes of float
delay(1000); // Send every second
}
Arduino 2 code:
#define LED_PIN 2 // LED connected to pin 2
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600); // Start Serial communication
}
void loop() {
if (Serial.available() >= sizeof(float)) { // Ensure 4 bytes are available
float receivedTemp;
Serial.readBytes((char *)&receivedTemp, sizeof(float)); // Read 4 bytes
// LED Control based on temperature
if (receivedTemp > 25.0) {
digitalWrite(LED_PIN, HIGH); // Turn LED ON
} else {
digitalWrite(LED_PIN, LOW); // Turn LED OFF
}
Serial.print("Temperature Received: ");
Serial.println(receivedTemp); // Print the received float
}
}
2) I2C Module With connections


Comments
Post a Comment