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





Arduino 1 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


Arduino 1 code:

//Master Code
#include <Wire.h> //i2c library
int pushbutton=A0;
void setup()
{
  Wire.begin();
  pinMode(pushbutton,INPUT);
}
int x = 0;
void loop()
{
  Wire.beginTransmission(8); 
  x=digitalRead(pushbutton);
   Wire.write(x);                
  Wire.endTransmission();   
  delay(500);
}

Arduino 2 code:

//Slave Code
#include <Wire.h>
int led=13;
void setup()
{
  Wire.begin(8);                
  Wire.onReceive(receiveEvent); 
  Serial.begin(9600);
  pinMode(led,OUTPUT);
}
void loop()
{
  delay(100);
}
void receiveEvent(int howMany)
{
  int x = Wire.read();    
  Serial.println(x); 
 if (x==1)
 {
   digitalWrite(led,HIGH);
 }
 else
 {
   digitalWrite(led,LOW);
 } 
}

Comments

Popular posts from this blog

MIMO Antenna Parameters

Meander Line Calculator

CIRCULAR PATCH ANTENNA CALCULATOR