Humidity sensor as PWM controller

Hi

I am using a humidity sensor to control the PWM - connected to Shape memory alloys (or for test a LED)
I am having some trouble with this.

I have no trouble getting the sensor to work and give me numbers, but I do not seem to be able to connect these to make my LED fade.

In connection I am using a TIP120 to control the voltage.
I have tried various codes, but I do not seem to make it work. With this one I get all the correct numbers, but somehow it’s not transferred onto my LED.

Can anyone help?

THANK YOU :slight_smile:

#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN 2 //defining my input pin

#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);

int Sensor = 2;
int SMA = 9;

int PWM = 0;
float SMAPower = 0;
int humMin = 0;
int humMax = 100;

void setup () {

pinMode(Sensor, INPUT);
pinMode(SMA, OUTPUT);

Serial.begin(9600);
Serial.println(“DHT22 test”);
Serial.println(“RH\tTemp (C)”);

dht.begin();

}

void loop() {

float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) { // check if a read fails, then exit and start over. isnan returns 1, if there is no read
Serial.println(“Failed to read from DHT sensor!”);
return;

}

Serial.println(); //prints the following in new lines
Serial.print(h); Serial.print("%\t\t");
Serial.print(t); Serial.print("*C\t");
Serial.print(SMAPower);

if ((h >= humMin) || (h <= humMax)) {
PWM = map(h,humMin,humMax,0,255);

SMAPower = 255 - PWM;

analogWrite(SMA,SMAPower); //sending the mapped data through the pin

}

delay(500);
}