Prevent consecutive duplicate values without a trigger
The INSERT itself, without a trigger, can avoid inserting the same value as the last one for the same experiment in the order of IDs. For instance, if $1 is the experiment and $2 the value:
INSERT INTO new_samples(experiment,value)
SELECT $1, $2 WHERE NOT EXISTS
 (SELECT 1 FROM new_samples
   WHERE id=(SELECT max(id) FROM new_samples WHERE experiment=$1)
     AND value=$2);

If there were multiple sessions that inserted concurrently for the same experiment, there would be a potential race condition, because the SELECT within the INSERT won't see a just-inserted row from a concurrent transaction that hasn't committed yet. But there is the same race condition with a trigger or a check constraint that tries to look beyond the row being modified or inserted.
Race conditions can be handled by using the serializable isolation level (auto-aborting conflicting transactions) or pessimistic locking (lock out other writers before doing the operation, effectively forcing a serialization).