I am trying to read GSR values from Generic CJMCU 6701 Arduino compatible sensor and Arduino UNO.
Following are the connections I have tried -
Sensor -> Arduino
+5V ->+5V
GND->GND
OUT -> A0
CS-> D10
MIS->D12
SCK-> D13
I wrote the following code to read the values -
#include <SPI.h>
int sensor_in =A0;
int raw=0;
int Vin=5;
float Vout=0;
float gsr=0;
void setup() {
pinMode(12, INPUT); //MISO
pinMode(13, OUTPUT); //CLOCK PIN
digitalWrite(10, HIGH); // ensure Slave select stays high
Serial.begin(9600);
SPI.begin();
}
void loop() {
// enable Slave Select
digitalWrite(10, LOW); // enable communication with slave
delay(500);
raw= SPI.transfer(0x00);// read from sensor
Serial.println(raw); // display reading on serial monitor
// disable Slave
digitalWrite(10, HIGH);
Vout = (Vin * raw) / 1023; // Convert Vout to volts
gsr = 100*(1 / ((Vin / Vout) - 1));
Serial.println(gsr);
delay(1000);
}
The only values being displayed is 0. Please help me to rectify it and/or share any related resources that might be useful.