https://dl.espressif.com/dl/package_esp32_index.json
int led=19;
int button=21;
int button_bit;
void setup() {
Serial.begin (9600);
pinMode(led,OUTPUT);
pinMode (button, INPUT);
// put your setup code here, to run once:
}
void loop() {
button_bit = digitalRead(button);
Serial.print(button_bit);
delay (100);
if (button_bit == 1)
{
digitalWrite(led,HIGH);
}
else {
digitalWrite (led,LOW);
}
// put your main code here, to run repeatedly:
}
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
byte light;
BluetoothSerial SerialBT;
void setup() {
Serial.begin(115200);
SerialBT.begin("espCHRIS"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
pinMode(19, OUTPUT);
}
void loop() {
if (SerialBT.available()) {
light = SerialBT.read();
delay(20);
}
if (light == 'ON'){
digitalWrite(19, HIGH);
}
else if (light == '0'){
digitalWrite(19, LOW);
}
}
after uploading codes to my esp 32 i first configured an android application used to communicate with microcontroller
import time
from machine import Pin
print ("hello chris")
pin2 = Pin(2, Pin.OUT)
while True:
pin2.on()
time.sleep_ms(800)
pin2.off()
time.sleep_ms(700)