**1. Introduction**

In this demo, I will make a simple Machine Learning - Artificial neural network system using Arduino ESP32. Certainly, I will not use ESP32 for training process; instead, i will use Python + numpy for training process. After training, I will use the result weights will be used by ESP32 for output calculation based on input.

Artificial neural network (ANN) systems are inspired by the biological neural networks. These systems can learn to do tasks by considering examples, without task-specific programming.

**One of most famous methods for ANN training is Backpropagation. You can refer here.**

In this demo: ESP32 with 2 buttons (B1 and B2) with possible states: pressed (0) or released (1) and there is 1 LED output with possible state state on (1) or off (0). The LED output can be set based on the state of input.

B1 | B2 | LED |
---|---|---|

pressed | pressed | off |

pressed | released | on |

released | pressed | on |

released | released | off |

**Figure: state of LED based on state of buttons**

**Figure: ANN structure of demo**

**2. Hardware**

Here we set input pins as INPUT_PULLUP so the schematic is simple and we can re-use the schematic in Demo 21.

**Figure: hardware connections**

[ESP32 GIO12 - BUTTON 1 - GND]

[ESP32 GIO13 - BUTTON 2 - GND]

[ESP32 GIO14 - LED - GND]

**3. Software**

**3.1 ANN is implemented by Python + numpy**

I used the code here.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | import numpy as np epochs = 10000 # Number of iterations inputLayerSize, hiddenLayerSize, outputLayerSize = 2, 3, 1 L = 0.1 # learning rate X = np.array([[0,0], [0,1], [1,0], [1,1]]) # Buttons states array Y = np.array([ [0], [1], [1], [0]]) # LED states array def sigmoid (x): return 1/(1 + np.exp(-x)) # activation function # weights on layer inputs Wh = np.random.uniform(size=(inputLayerSize, hiddenLayerSize)) Wz = np.random.uniform(size=(hiddenLayerSize,outputLayerSize)) for i in range(epochs): H = sigmoid(np.dot(X, Wh)) # calculate forward part Z = np.dot(H,Wz) # E = Y - Z # calculate error dZ = E * L # delta Z Wz += H.T.dot(dZ) # calculate backpropagation part dH = dZ.dot(Wz.T) * sigmoid_deriv(H) # Wh += X.T.dot(dH) # update hidden layer weights print("**************** error ****************") print(E) print("***************** output **************") print(Z) print("*************** weights ***************") print("input to hidden layer weights: ") print(Wh) print("hidden to output layer weights: ") print(Wz) |

**Figure: training process and weights output**

**3.2 Arduino ESP32**

The Arduino code just do the forward part to calculate the output when getting the inputs.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include <math.h> #define B1 12 #define B2 13 #define LED 14 int X[1][2] = {{1,0}}; /*these matrices was calculated by python */ float W1[2][3] = {{0.74000854, 4.47769531, -0.98692059}, {0.83034991, 4.48772758, -0.55733578}}; float W2[3][1] = {{-6.17234487}, {4.8835918}, {1.28875386}}; float Wo1[1][3]; float sum = 0; float Y = 0; /*sigmoid function*/ float sigmoid (float x) { return 1/(1 + exp(-x)); } void setup() { Serial.begin(115200); pinMode(B1, INPUT_PULLUP); pinMode(B2, INPUT_PULLUP); pinMode(LED, OUTPUT); digitalWrite(LED, LOW); } void loop() { X[0][0] = digitalRead(B1); X[0][1] = digitalRead(B2); printf("B1 = %d, B2 = %d\n", X[0][0], X[0][1]); /* calculate forward part based on weights */ //hidden layer for(int i=0; i<1; i++) { for(int j=0;j <3; j++) { for(int k=0; k<2; k++) { sum += X[i][k]*W1[k][j]; } Wo1[i][j] = sigmoid(sum); sum = 0; } } //output layer for(int i=0; i<1; i++) { for(int j=0;j <1; j++) { for(int k=0; k<3; k++) { Y += Wo1[i][k]*W2[k][j]; } } } printf("Y = %f\n", (Y)); Y = round(Y); digitalWrite(LED, int(Y)); Y = 0; delay(1000); } |

**4. Result**

## 71 Comments

def sigmoid_deriv(x):

f = sigmoid(x)

return f * (1 - f)

source : https://stackoverflow.com/questions/10626134/derivative-of-sigmoid

Great post.

Very helpfull to start experiments.

Lot of your other posts are also well done.

Thx.

this is feed forward part so you will not see derivative.

I am wrtting new blog about machine learning.

It is http://www.fossreview.com/

Hope you like it :)

Regards

ccna Training in Chennai

ccna Training institute in Chennai

Python Training in Chennai

Python Classes in Chennai

Angularjs Training in Chennai

ccna Training in Velachery

ccna Training in Tambaram

ExcelR data science

data analytics course in Bangalore

data analytics course in Bangalore

SAP training in Kolkata

Best SAP training in Kolkata

SAP training institute in Kolkata

Correlation vs Covariance

Simple linear regression

Correlation vs Covariance

Simple linear regression

Robotic Process Automation (RPA) Training in Chennai | Robotic Process Automation (RPA) Training in anna nagar | Robotic Process Automation (RPA) Training in omr | Robotic Process Automation (RPA) Training in porur | Robotic Process Automation (RPA) Training in tambaram | Robotic Process Automation (RPA) Training in velachery

Data Science Course in Hyderabad

Data Analyst CourseSimple Linear Regression

Correlation vs covariance

data science interview questions

KNN Algorithm

Logistic Regression explained

The-interface is the perfect solution for SAP training. Interface is one of best SAP training in Kolkata, India. We are providing very prompt and world-class SAP training, SAP training in Kolkata. It is also a renowned SAP training institute in Kolkata.

The Interface is a unique SAP institute in Kolkata, and a SAP training center in Kolkata. It also gives best guidance on SAP through online training and thus,

it is considered as the Best SAP training in Kolkata.You can here directly contact the institute for SAP training in Kolkata and for any information. So keep visiting our websites to get update on regular basis.

Correlation vs Covariance

Simple Linear Regression

data science interview questions

KNN Algorithm

Logistic Regression explained

graphic design courses in tambaram

graphic design courses in Porur

Artificial Intelligence Course in Tambaram

Artificial Intelligence Course in Velachery

Artificial Intelligence Course in porur

how to convert list to string in python

data structures using python

polymorphism in oops

numpy in python

python interview questions and answers for testers

convert string to list python

Join 360digiTMG for the best courses

data science training in Pune

how to improve testing skills

about banking process

languages for data science

what is php used for in web development

digital marketing interview questions and answers for freshers

hadoop interview questions and answers pdf

vé máy bay vietjet từ hàn quốc về việt nam

vé máy bay hà nội sài gòn tháng 4

mua vé máy bay đi hà nội giá rẻ

giá vé máy bay đi cam ranh

gia ve may bay di my

Data Analytics Courses in Bangalore

Data Science Course in India

https://socialprachar.com/

Artificial Intelligence Training and Course in Hyderabad

data scientist training and placement

Visit us @

Data Science Training in Pune

Python Classes in Pune

Data Science Training in Bhilai

AI Patasala Data Science Training

An obligation of appreciation is all together for sharing.data analytics course in gwalior

data science training in gorakhpur

data science course in lucknow

data science course in borivali

data analytics course in borivali

Data Science Course in Delhi

Data Scientist Course in Delhi

Data Science Course in Bangalore with Placement

Data Science Course in Jaipur

For more info visit Spoken english class in bahrain

For more info visit Spoken English classes in Kuwait

Data Analytics Courses in Nashik

Data Analytics Courses in Delhi

Data Analytics Courses in Mumbai

Data Analytics Courses In Kochi

Data Analytics Courses In Dubai

Data Analytics Courses in Canada